<?php

ob_start('ob_gzhandler');
session_start();

include("./includes/settings.inc");
require("./includes/detections.inc");

compatdetect();

if ($_SESSION['newsession']==!"false"){
if (stristr($_SERVER["HTTP_USER_AGENT"], 'Gecko')) {
$_SESSION['renderer']="gecko";
}
elseif (stristr($_SERVER["HTTP_USER_AGENT"], 'MSIE')) {
$_SESSION['renderer']="trident";
}
}
//Database queries.
$max = mysql_query("SELECT MAX(editionid) FROM enlight_stories");
$max = mysql_fetch_row($max);

$res2 = mysql_query("SELECT * FROM enlight_stories WHERE editionid = '$max[0]' ORDER BY id ASC LIMIT 0, 4");
$stor1 = mysql_fetch_row($res2);
$stor2 = mysql_fetch_row($res2);
$stor3 = mysql_fetch_row($res2);
$stor4 = mysql_fetch_row($res2);
mysql_free_result($res2);

$res3 = mysql_query("SELECT * FROM enlight_columns ORDER BY id ASC LIMIT 0, 1");
$dbc = mysql_fetch_array($res3);
mysql_free_result($res3);

$res4 = mysql_query("SELECT * FROM enlight_polls ORDER BY id ASC LIMIT 0, 1");
$dbp = mysql_fetch_row($res4);
mysql_free_result($res4);

if ($_COOKIE['votedid']==$dbp['0']){
$res5 = mysql_query("SELECT * FROM enlight_polls_results ORDER BY id ASC LIMIT 0, 1");
$dbpr = mysql_fetch_row($res5);
mysql_free_result($res5);
}

mysql_close();

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<?xml-stylesheet type=\"text/css\" href=\"./CSS/$_SESSION[renderer]-$_SESSION[resolution].css\"?>\n";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?=$language?>">
<head>
<title><?=$sitename?>, editie <?=$stor1['7']?>. Powered by Enlightener v<?=$softversion?> <?=$softstate?></title>
<?php
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"./CSS/$_SESSION[renderer]-$_SESSION[resolution].css\" />\n";
?>
<script language="JavaScript" src="./JS/main.js" type="text/javascript"></script>
</head>

<?php
if ($_SESSION['newsession']==!"false"){

echo"<body onload=\"resredir();\">\n";

$_SESSION['newsession']="false";
}
else{
echo "<body>";
}
?>
<div id="top">
<?php
if ($_SESSION['renderer'] == "gecko"){
echo "<object id=\"button1\" data=\"./images/home-button3.svg.php\" type=\"image/svg+xml\">Ga naar hoofdpagina.</object>";
}
else {
echo "<a href=\"./index.php\"><img id=\"button1\" src=\"./images/home-button3.png\" alt=\"Ga naar hoofdpagina.\" /></a>";
}
?>
</div>

<div id="topright">
<?php
if ($_SESSION['login']==!"true") {
echo "<form action=\"post\" name=\"login\" onsubmit=\"ajaxlogin();return false;\">
Gebruikersnaam:<br />
<input type=\"text\" id=\"username\" name=\"username\" size=\"20\" /><br />
Wachtwoord:<br />
<input type=\"password\" id=\"password\" name=\"password\" size=\"20\" /><br />
<input type=\"submit\" id=\"submit\" name=\"submit\" value=\"Inloggen!\" />
</form>
<div id=\"loginstate\"></div>";
}
else {
echo "Ingelogd als, $_SESSION[uname]!<br />";
echo "Deadline editie \n";
echo "<div id=\"deadline\"></div>";
}
?>
</div>

<div id="right">bla3</div> //Ads by Goooooooooooooooooooogle!

<div id="bottomright">
Enlightener v<?=$softversion?> <?=$softstate?><br />
Software, GNU General Public License v2.
<br />
Graphics, Copyrighted 2006 <?=$admin?>.<br />
Content, Creative Commons 2006 <?=$admin?>.<br />
</div>

<div id="intro">
<div id="introheader">Editie #<?=$stor1['7']?> <?=$sitename?></div>
Welkom, deze editie in <?=$sitename?> o.a.:
<ul>
<li><?=$stor1['4']?></li>
<li><?=$stor2['4']?></li>
<li><?=$stor3['4']?></li>
<li><?=$stor4['4']?></li>
</ul>
</div>

<div id="story1"><div class="header"><?=$stor1['4']?></div>
<div class="story">
<?=$stor1[5]?>
</div>
<div class="storyfooter"><a href="./showstory.php?id=<?=$stor1[0]?>">Lees verder..</a> Geplaats op <?=$stor1[1]?> uur, door: <?=$stor1[2]?>.</div>
</div>

<div id="story2"><div class="header"><?=$stor2['4']?></div>
<div class="story">
<?=$stor2['5']?>
</div>
<div class="storyfooter"><a href="./showstory.php?id=<?=$stor2['0']?>">Lees verder..</a> Geplaats op <?=$stor2['1']?> uur, door: <?=$stor2['2']?>.</div>
</div>

<div id="story3"><div class="header"><?=$stor3['4']?></div>
<div class="story">
<?=$stor3['5']?>
</div>
<div class="storyfooter"><a href="./showstory.php?id=<?=$stor3['0']?>">Lees verder..</a> Geplaats op <?=$stor3['1']?> uur, door: <?=$stor3['2']?>.</div>
</div>

<div id="story4"><div class="header"><?=$stor4['4']?></div>
<div class="story">
<?=$stor4['5']?>
</div>
<div class="storyfooter"><a href="./showstory.php?id=<?=$stor4['0']?>">Lees verder..</a> Geplaats op <?=$stor4['1']?> uur, door: <?=$stor4['2']?>.</div>
</div>

<div id="poll"><div class="blueheader4"><?=$dbp['1']?></div>
<?php
$polloptions = array_slice($dbp, -6);
if ($_COOKIE['votedid']==$dbp['0']){
$pollresults = array_slice($dbpr, -6);

$total = $pollresults['0']+$pollresults['1']+$pollresults['2']+$pollresults['3']+$pollresults['4']+$pollresults['5'];

foreach ($polloptions as $opt){
if (!empty($opt)){
$nr = strpbrk($opt, '123456')-1;
$opt = str_replace(array(1, 2, 3, 4, 5, 6), "", $opt);
$percentage = $pollresults[$nr]/$total*100;
$percentage = round($percentage, 0);

echo "<div class=\"pollresult\">$opt <img src=\"./images/percentage.php?percentage=$percentage\" alt=\"$percentage\" /></div><br />\n";
}
}
}
else{
echo "<form action=\"post\" id=\"pollform\" name=\"$dbp[0]\">\n";

foreach ($polloptions as $opt) {
if (!empty($opt)){
$nr = strpbrk($opt, '123456');
$opt = str_replace(array(1, 2, 3, 4, 5, 6), "", $opt);
echo "<input type=\"radio\" id=\"polloption$nr\" name=\"option\" value=\"$nr\" onfocus=\"pollsubmit(this.id)\" /> $opt<br />\n";
}
}
echo "</form>\n";
}
?>
</div>

<div id="column"><div class="blueheader4"><?=$dbc['title']?></div>
<div class="story">
<?=$dbc['story']?>
</div>
<div class="storyfooter"><?=$dbc['datetime']?>, door <?=$dbc['author']?>.</div>
</div>

</body>
</html>